package com.chushouya.controller.order.admin;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.chushouya.order.dto.admin.order.OrderQuery;
import com.chushouya.order.dto.admin.order.OrderDataDTO;
import com.chushouya.order.dto.admin.order.OrderListDTO;
import com.chushouya.order.dto.admin.order.OrderLogicStatus;
import com.chushouya.order.dto.admin.order.UpdateOrderProductDTO;
import com.chushouya.order.service.admin.AdminOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@Slf4j
@Api(tags = ServiceType.PLATFORM + "平台订单管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/order")
public class OrderController {

    @Resource
    private AdminOrderService adminOrderService;

    @ApiOperation("获取订单列表接口")
    @GetMapping("/list")
    public Response<PageResult<OrderListDTO>> list(OrderQuery query) {
        return Response.success(adminOrderService.selectOrderList(query));
    }

    @ApiOperation("获取订单详细接口")
    @GetMapping("/detail")
    public Response<OrderDataDTO> orderDetail(Long orderId) {
        return Response.success(adminOrderService.selectOrderDetail(orderId));
    }

    @ApiOperation("获取订单各状态数量")
    @GetMapping("/orderStatusCount")
    public Response<List<OrderLogicStatus>> orderStatusCount(OrderQuery query) {
        return Response.success(adminOrderService.selectStatusCount(query));
    }

    /**
     * 更新订单产品信息
     */
    @ApiOperation("更新订单产品信息")
    @PostMapping("/updateOrderProduct")
    public Response<Void> updateOrderProduct(@RequestBody @Valid UpdateOrderProductDTO updateOrderProductDTO) {
        adminOrderService.updateOrderProduct(updateOrderProductDTO);
        return Response.success();
    }

}
